package cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.controller;

import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.entity.SoftwareCopyright;
import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.result.Result;
import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.service.SoftwareCopyrightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 软著控制器
 */
@RestController
@RequestMapping("/SoftwareCopyright")
public class SoftwareCopyrightController {
    @Autowired
    private SoftwareCopyrightService SoftwareCopyrightService;

    /**
     * 分页查询软著列表
     * @param pageNum 页码
     * @param pageSize 每页数量
     * @param params 查询条件
     * @return 分页结果
     */
    @GetMapping("/list")
    public Result list(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam Map<String, Object> params) {
        return SoftwareCopyrightService.list(pageNum, pageSize, params);
    }

    /**
     * 根据ID查询软著
     * @param id 软著ID
     * @return 软著信息
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        return SoftwareCopyrightService.getById(id);
    }

    /**
     * 新增软著
     * @param params 参数，包含SoftwareCopyright和teacherIds
     * @return 结果
     */
    @PostMapping
    public Result add(@RequestBody Map<String, Object> params) {
        SoftwareCopyright SoftwareCopyright = new SoftwareCopyright();
        SoftwareCopyright.setName((String) params.get("name"));
        SoftwareCopyright.setDate(new java.util.Date((Long) params.get("date")));
        SoftwareCopyright.setIntroduction((String) params.get("introduction"));
        SoftwareCopyright.setRemarks((String) params.get("remarks"));

        @SuppressWarnings("unchecked")
        List<Integer> Ids = (List<Integer>) params.get("Ids");

        return null;
    }

    /**
     * 更新软著
     * @param params 参数，包含SoftwareCopyright和teacherIds
     * @return 结果
     */
    @PutMapping
    public Result update(@RequestBody Map<String, Object> params) {
        SoftwareCopyright SoftwareCopyright = new SoftwareCopyright();
        SoftwareCopyright.setName((String) params.get("name"));
        SoftwareCopyright.setDate(new java.util.Date((Long) params.get("date")));
        SoftwareCopyright.setIntroduction((String) params.get("introduction"));
        SoftwareCopyright.setRemarks((String) params.get("remarks"));

        @SuppressWarnings("unchecked")
        List<Integer> Ids = (List<Integer>) params.get("Ids");

        return null;
    }

    /**
     * 删除软著
     * @param id 软著ID
     * @return 结果
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        return SoftwareCopyrightService.delete(id);
    }

    /**
     * 批量更新状态
     *
     * @param params 参数，包含ids和status
     */
    @PutMapping("/batchUpdateStatus")
    public void batchUpdateStatus(@RequestBody Map<String, Object> params) {
        @SuppressWarnings("unchecked")
        List<Integer> ids = (List<Integer>) params.get("ids");
        Integer status = (Integer) params.get("status");

    }
}
